(function () {
    axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

    const form = document.querySelector(".rg_center .rg_form form");
    form.addEventListener("submit", async function (e) {
        e.preventDefault();
        // console.log($(this).serialize())
        // const data = $(this).serialize() + '&description=ok'
        const data = $(this).serialize().split('&').map(item => item.replace(/=/, ',')).join(',').split(',')
        const obj = {}
        for (let i = 0; i < data.length; i = i + 2) {
            obj[data[i]] = data[i + 1]
        }
        obj.sex = obj.sex === '1' ? 1 : 0
        obj.vip = obj.vip === '1' ? 1 : 0
        const zhuce = axios.create({
            headers: { 'Content-Type': 'application/json' }
        })
        const { data: data1 } = await zhuce.post('/user/reg', obj)
        console.log(data1);
        if (!data1.success) return alert(data1.msg)
        alert(data1.msg)
        location.href = "../登录/login.html"
        // axios({
        //     method: "POST",
        //     url: "http://124.223.14.236:3001/api/user/reg",
        //     headers: {
        //         'Content-Type': 'application/json'
        //     },
        //     data: JSON.stringify(obj),
        // }).then(function (res) {
        //     console.log(res);
        //     if (!res.data.success) return alert("注册失败：" + res.data.msg);
        //     alert("注册成功");
        //     location.href = "../登录/login.html";
        // })
    });



})();